package com.event.core.context;

import com.event.common.face.IEventHandle;
import com.event.common.model.UpdateAfterEvent;
import com.event.common.model.UpdateBeforeEvent;
import com.event.core.listener.EventListener;
import com.google.common.eventbus.EventBus;

/*
 * @description 事件上下文
 * @author Bing
 * @date 2024/10/8 14:07
 **/
public class EventContext {
    /**
     * 事件总线
     */
    private EventBus eventBus = new EventBus();

    public EventContext(IEventHandle eventHandle) {
        eventBus.register(new EventListener(eventHandle));
    }

    /**
     * 更新前事件
     * @param updateBeforeEvent
     */
    public void updateBeforeEvent(UpdateBeforeEvent updateBeforeEvent){
        eventBus.post(updateBeforeEvent);
    }

    /**
     * 更新后事件
     * @param updateAfterEvent
     */
    public void updateAfterEvent(UpdateAfterEvent updateAfterEvent){
        eventBus.post(updateAfterEvent);
    }
}
